<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class MY_Controller extends MX_Controller {

    protected $_data = array();

    public function __construct() {
        parent::__construct();
        $this->system_log = My_Logs::instance(My_Logs::SERVER_LOG);
        $this->system_log->process_id = $this->session->userdata('user_id');
    }

    public function __destruct() {
        //$this->system_log->log_sql_query();
    }

    public function is_logged_in() {
        if (!$this->session->userdata('username')) {
            redirect('user/auth/login');
        }
        $this->_data['username'] = $this->session->userdata('username');
    }

    public function encode_pwd($encrypted) {
        $key = '';
        return md5($key . $encrypted);
    }

    public function createID() {
        $chars = "abcdefghijkmnopqrstuvwxyz023456789";
        srand((double) microtime() * 1000000);
        $i = 0;
        $ID = '';
        while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $ID = $ID . $tmp;
            $i++;
        }

        return time() . '-' . strtoupper($ID);
    }
    
    public function createPassword() {
    	$chars = "abcdefghijkmnopqrstuvwxyz023456789";
    	srand((double) microtime() * 1000000);
    	$i = 0;
    	$ID = '';
    	while ($i <= 7) {
    		$num = rand() % 33;
    		$tmp = substr($chars, $num, 1);
    		$ID = $ID . $tmp;
    		$i++;
    	}
    
    	return strtoupper($ID);
    }
}

?>
